<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<strong><%@ taglib prefix="c"
                   uri="http://java.sun.com/jsp/jstl/core" %></strong>
<!DOCTYPE html>
<html class="x-admin-sm">

<head>
    <meta charset="UTF-8">
    <title>艺术家新增</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <link rel="stylesheet" href="/xAdmin/css/font.css">
    <link rel="stylesheet" href="/xAdmin/css/xadmin.css">
    <link rel="stylesheet" href="/xAdmin/lib/layui/css/layui.css"  media="all">
    <script type="text/javascript" src="https://cdn.bootcss.com/jquery/3.2.1/jquery.min.js"></script>
    <script type="text/javascript" src="/xAdmin/lib/layui/layui.js" charset="utf-8"></script>
    <script type="text/javascript" src="/xAdmin/js/xadmin.js"></script>
    <!-- 让IE8/9支持媒体查询，从而兼容栅格 -->
    <!--[if lt IE 9]>
    <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
    <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->
</head>
<body>
<div class="layui-fluid">
    <div class="layui-row">
        <form method="post" class="layui-form" lay-filter="example">
            <input type="hidden" value="${art.id}" id="artid">
            <input type="hidden" value="${art.description}" id="descriptiondesc">
            <input type="hidden" value="${art.style1}" id="artStyle1">
            <div class="layui-form-item">
                <label for="name" class="layui-form-label">
                    艺术品名称
                </label>
                <div class="layui-input-inline">
                    <input type="text" id="name" name="name" required="" lay-verify="required"
                           autocomplete="off" class="layui-input" value="${art.name}">
                </div>
            </div>

            <div class="layui-form-item">
                <div class="layui-inline">
                    <label for="marketprice" class="layui-form-label">
                        价格
                    </label>
                    <div class="layui-input-inline">
                        <input type="text" id="marketprice" name="marketprice" required="" lay-verify="required"
                               autocomplete="off" class="layui-input" value="${art.marketprice}">
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <label for="number" class="layui-form-label">
                    数量
                </label>
                <div class="layui-input-inline">
                    <input type="text" id="number" name="number" required="" lay-verify="required"
                           autocomplete="off" class="layui-input" value="${art.number}">
                </div>
            </div>
            <div class="layui-form-item">
                <label for="number" class="layui-form-label">
                    规格
                </label>
                <div class="layui-input-inline">
                    <input type="text" id="norms" name="norms" required="" lay-verify="required"
                           autocomplete="off" class="layui-input" value="${art.norms}">
                </div>
            </div>
            <div class="layui-form-item">
                <label for="number" class="layui-form-label">
                    品相
                </label>
                <div class="layui-input-inline">
                    <input type="text" id="phase" name="phase" required="" lay-verify="required"
                           autocomplete="off" class="layui-input" value="${art.phase}">
                </div>
            </div>
            <div class="layui-form-item">
                <label for="number" class="layui-form-label">
                    材质
                </label>
                <div class="layui-input-inline">
                    <input type="text" id="textureOfMaterial" name="textureOfMaterial" required="" lay-verify="required"
                           autocomplete="off" class="layui-input" value="${art.textureOfMaterial}">
                </div>
            </div>
            <div class="layui-form-item">
                <label for="number" class="layui-form-label">
                    年代
                </label>
                <div class="layui-input-inline">
                    <input type="text" id="years" name="years" required="" lay-verify="required"
                           autocomplete="off" class="layui-input" value="${art.years}">
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">大类</label>
                <div class="layui-input-block" style="width: 100px">
                    <select name="style" id="style"  lay-verify="" lay-filter="style">
                        <c:forEach  items="${style}" var="style">
                            <option value="${style.stylevalue}"  title="${style.id}" <c:if test="${art.style==style.id}"> selected </c:if>
                            >${style.styledesc}</option>
                        </c:forEach>
                    </select>
                </div>
            </div>

<%--            <div class="layui-form-item">--%>
<%--                <label class="layui-form-label">小类</label>--%>
<%--                <div class="layui-input-block" style="width: 100px">--%>
<%--                    <select name="style1" id="style1"  lay-verify="" lay-filter="style1">--%>
<%--                        <option  value="${art.style1}">${style1desc} </option>--%>
<%--                    </select>--%>
<%--                </div>--%>
<%--            </div>--%>


            <div class="layui-form-item">
                <label class="layui-form-label">状态</label>
                <div class="layui-input-block" style="width: 100px">
                    <select name="salestate" id="salestate"  lay-verify="" >
                        <c:forEach  items="${salestate}" var="salestate">
                            <option value="${salestate.stylevalue}" data-id="${salestate.id}" <c:if test="${art.salestate==salestate.stylevalue}"> selected </c:if>
                            >${salestate.styledesc}</option>
                        </c:forEach>
<%--                        <option value="0" <c:if test="${art.salestate=='0'}"> selected </c:if>--%>
<%--                        >上架</option>--%>
<%--                        <option value="1" <c:if test="${art.salestate=='1'}"> selected </c:if>--%>
<%--                        >已被下单</option>--%>
<%--                        <option value="2" <c:if test="${art.salestate=='2'}"> selected </c:if>--%>
<%--                        >已售</option>--%>
<%--                        <option value="3" <c:if test="${art.salestate=='3'}"> selected </c:if>--%>
<%--                        >下架</option>--%>
<%--                        <option value="4" <c:if test="${art.salestate=='4'}"> selected </c:if>--%>
<%--                        >失效</option>--%>
                    </select>
                </div>
            </div>
            <div class="layui-form-item">
                <label for="description" class="layui-form-label">
                    <button type="button" class="layui-btn" id="userInfo" name="userInfo" onclick="openL()">
                        <i class="layui-icon"></i>作者
                    </button>
                </label>
                <div class="layui-input-inline" style="top: 8px;">
                    <input type="hidden" id="userid" value="${art.userid}">
                    <input type="text" id="userdesc" name="userdesc" required="" lay-verify="required"
                           autocomplete="off" class="layui-input" value="${art.userdesc}" disabled="disabled">
                </div>
            </div>
            <div class="layui-form-item">
                <label for="description" class="layui-form-label">
                    <button type="button" class="layui-btn" id="file" name="file">
                        <i class="layui-icon">&#xe67c;</i>上传图片
                    </button>
                </label>
                <div class="layui-input-block">
                    <input type="hidden" id="mainpicShowValue" value="">
                    <img src="${art.mainpic}" id="mainpicShow">
                </div>
            </div>
            <div class="layui-form-item">
                <label for="description" class="layui-form-label">
                    作品简介
                </label>
                <div class="layui-input-block" >
                    <textarea name="description" style="width: 200px" id="description" placeholder="请输入内容" class="layui-textarea" ></textarea>
                </div>
            </div>


            <div class="layui-form-item">
                <label class="layui-form-label">
                </label>
                <button type="button" class="layui-btn" lay-filter="add"  onclick="Issubmit()">
                    确定
                </button>
            </div>

        </form>
    </div>
</div>
<script>

    layui.use('form', function(){
        var form = layui.form; //只有执行了这一步，部分表单元素才会自动修饰成功
        // form.on('select(style)', function(data){
        //     $("#style1").empty();//清空下拉框的值
        //     var fId = data.elem[data.elem.selectedIndex].title;
        //     $.ajax({
        //         url:'/ajaxData/styleQuery?level=2&fId='+fId,
        //         type:'GET',
        //         dataType:'text',
        //         contentType: 'application/json',
        //         timeout:2000,
        //         success:function(data){
        //             var datas =JSON.parse( data );
        //             if(datas.oper_res){
        //                 var artStyle1 =$('#artStyle1').val();
        //                 $.each(datas.data, function (index, item) {
        //                     if(artStyle1==item.stylevalue)
        //                         $('#style1').append("<option value='"+item.stylevalue+"' selected >"+item.styledesc+"</option>");
        //                     else
        //                         $('#style1').append("<option value='"+item.stylevalue+"'>"+item.styledesc+"</option>");
        //                 });
        //                 form.render('select');
        //                 // parent.layui.form('select').render();//重新渲染 固定写法
        //             }
        //         }
        //     });
        // });
        form.render('select');
        var descs = $("#descriptiondesc").val();
        form.val('example',{"description":descs});
    });

    layui.use('upload', function(){
        var upload = layui.upload;
        //执行实例
        var uploadInst = upload.render({
            elem: '#file' //绑定元素
            ,url: '/ajaxData/uploadFile' //上传接口
            ,done: function(res){
                //上传完毕回调
                $("#mainpicShow").attr("src", res.srcPath);
                $("#mainpicShowValue").val(res.showPath);

            }
            ,error: function(){
                //请求异常回调
                console.log("请求异常回调");
            }
        });
    });


    function Issubmit(){
        var name =  $('#name').val();
        var marketprice =  $('#marketprice').val();
        var number =  $('#number').val();
        var artid= $('#artid').val();
        var mainpic =  $('#mainpicShowValue').val();
        var description =  $('#description').val();
        var salestate =$('#salestate option:selected').val();
        var style =$('#style option:selected').val();
        // var style1 =$('#style1 option:selected').val();
        var userid=$('#userid').val();
        var norms=$('#norms').val();
        var years=$('#years').val();
        var phase=$('#phase').val();
        var textureOfMaterial=$('#textureOfMaterial').val();
        var date =null;
        if(artid==null||artid==""){
            data = {
                name:name,
                marketprice:marketprice,
                number:number,
                mainpic:mainpic,
                salestate:salestate,
                description:description,
                userid:userid,
                norms:norms,
                style:style,
                textureOfMaterial:textureOfMaterial,
                phase:phase,
                years:years
            };
        }else{
            data = {
                id:artid,
                name:name,
                marketprice:marketprice,
                number:number,
                mainpic:mainpic,
                salestate:salestate,
                description:description,
                userid:userid,
                norms:norms,
                style:style,
                textureOfMaterial:textureOfMaterial,
                phase:phase,
                years:years
            };
        }

        $.ajax({
            url:"/tBizArt/saveOrUpdate",
            type:'post',
            dataType:'text',
            contentType: 'application/json',
            data:JSON.stringify(data),
            timeout:2000,
            success:function(data){
                // console.log( JSON.parse( data ));
                var datas =JSON.parse( data );
                var layer = parent.layui.layer;
                if(datas.oper_res == 'success')
                    layer.msg('操作成功!',{icon:1,time:1000});
                else
                    layer.msg('操作失败!',{icon:1,time:1000});
                var index = parent.layer.getFrameIndex(window.name);
                parent.layer.close(index);
            },
            error:function () {
                var layer = parent.layui.layer;
                layer.msg("操作失败",{icon:1,time:1000});
            }
        })
    }

    function openL(){
        layui.use('layer', function(){
            var layer = parent.layui.layer;
            var index = layer.open({
                title: "作品作者",
                type: 2,
                area: ["900px","700px"],
                content: '/tBizArt/userList',
                btn: ['确定', '关闭'],
                yes: function (index, layero) {
                    var obj = $(layero).find("iframe")[0].contentWindow;
                    $('#userid').val(obj.userid);
                    $('#userdesc').val(obj.userdesc);
                    layer.close(index);
                }
            });
        });
    }

</script>

</body>

</html>
